var EX = {
    path: 'http://localhost:8080/',
};

//前端AES加密调用方式
//sendmi("内容");
function sendmi(keys) { //加密
    var mikey = '1234567890123456'; // 密钥 长度16
    var iv = 'qwertyuiopasdfgh'; // 偏移量 长度16
    var info = "";
    for (var key in keys) {
        //console.log(key + ":" + keys[key])
        info = info + key + ":" + keys[key] + ",";
    }
    info = info.substring(0, info.length - 1);
    //console.log("加密前："+info);
    var mi = encodeAesString(info, mikey, iv);
    //console.log("加密后："+mi);
    return mi + "";
}

//前端AES解码调用方式
//Decrypt("内容");
function unlockmi(keys) { //加密
    var key = 'abcdef0123456789'; // 密钥 长度16
    var iv = '0987654321abcdef'; // 密钥 长度16
    var info = decodeAesString(keys, key, iv);
    var mi = $.parseJSON(info);
    return mi;
}

//加密
function encodeAesString(data, key, iv) {
    var key = CryptoJS.enc.Utf8.parse(key);
    var iv = CryptoJS.enc.Utf8.parse(iv);
    var encrypted = CryptoJS.AES.encrypt(data, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    //返回的是base64格式的密文
    return encrypted;
}

//解密
// encrypted 为是base64格式的密文
function decodeAesString(encrypted, key, iv) {
    var key = CryptoJS.enc.Utf8.parse(key);
    var iv = CryptoJS.enc.Utf8.parse(iv);
    var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    return decrypted.toString(CryptoJS.enc.Utf8);
}

/**
 * 默认的cookie写入方法
 * @param name
 * @param value
 */
function setCookie(name, value) {
    var Days = 1;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/leasingCalculator";
}

/**
 * 获取Cookie中的值
 * @param objName
 * @returns
 */
function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) {
            return decodeURI(temp[1]);
        }
    }
}